
class cassandra {

  include cassandra::param
  notify { "Current version is ${cassandra::param::version}": }

  $home_path = '/home/cassandra'

  user{
    'cassandra':
        ensure => present,
        gid => 'root',
        system => true,
        home => $home_path,
  }

  File{
    owner => 'cassandra',
    group => 'root',
  }

  Exec{
    user => 'cassandra',
  }

  $tar_path = "${home_path}/tzfiles"
  $java_path = "${home_path}/java"
  $cassandra_path = "${home_path}/cassandra"
  $ops_path = "${home_path}/opsagent"
  $conf_path = "${home_path}/conf"
  $run_path = "${home_path}/run"

  file{
    "$home_path":
        ensure => directory,
        mode => 0770,
	require => User['cassandra'],
  } -> 
  file{
    "$tar_path":
	ensure => directory,
	mode => 0770,
  } ->
  file{["$conf_path",
     "$run_path"
    ]:
	ensure => directory,
	mode => 0770,
  } 

  cassandra::tzfile{"${cassandra::param::package_java}":
	path => $java_path,
	tarpath => $tar_path,
	require => File["$home_path"],
  }

  cassandra::tzfile{"${cassandra::param::package_cassandra}":
	path => $cassandra_path,
	tarpath => $tar_path,
	require => File["$home_path"],
	tag => 'tarball_inst',
	before => File["$cassandra_path/logs"],
  }

  -> file{'/etc/init.d/cassandra':
	owner => root,
	group => root,
	mode => 0755,
	content => template("cassandra/cassandra.erb")
  }


  cassandra::tzfile{"${cassandra::param::package_opsagent}":
	path => $ops_path,
	tarpath => $tar_path,
	require => File["$home_path"],
	tag => 'tarball_inst',
	before => File["$ops_path/log"],
  }
  -> file{"$ops_path/bin/start-cassandra":
	mode => 0755,
        content => template("cassandra/start-cassandra.erb");

	"$ops_path/bin/stop-cassandra":
        mode => 0755,
        content => template("cassandra/stop-cassandra.erb");

	'/etc/init.d/opsagent':
        owner => root,
        group => root,
        mode => 0755,
        content => template("cassandra/opsagent.erb")
  }

  file{["$cassandra_path/logs",
    "$ops_path/log"]:
        ensure => link,
        target => $run_path,
  }


/*
#update if required
  if file("","/dev/null") != ''{

    notify {"should do update":}
  }
*/
  

}

